<template>
	<view class="index-page with-tabbar">
		<view class="page-content">
			<!-- 个人信息 -->
			<view class="flex align-center bg-fff p-30" @click="toSet('/pages/setting/userSet')">
				<image class="head-img" v-if="userInfo.avatar"
					:src="userInfo.avatar.indexOf('https://') > -1 ? userInfo.avatar : baseUrl + userInfo.avatar"
					alt="" />
				<image class="head-img" v-else
					:src="userInfo.sex === '0' ? 'https://apitest.yijiangongxiang.com/template/nan.png' : 'https://apitest.yijiangongxiang.com/template/nv.png'"
					alt="" />
				<div class="ml-28">
					<div class="fontS32 color-1 font-weight lh-44">{{ userInfo.realName || '未认证' }}</div>
					<div class="fontS24 color-1 mt-4">{{ userInfo.phonenumber }}</div>
				</div>
				<div class="iconfont icon-youjiantou ml-auto"></div>
			</view>
			<view class=" bg-fff p-30 mt-20" v-if="!userInfo.cardNo" @click="toSet('/pages/auth/cardAuth')">
				<div class="flex align-center lh-50 ">

					<div class="fontS28 ">去认证</div>
					<div class="iconfont icon-youjiantou ml-auto"></div>
				</div>


			</view>
			<view class=" bg-fff p-30 mt-20">
				<div class="flex align-center lh-50 bor-b pb-20"
					@click="toSet('/pages/webView/webView?url=https://api.yijiangongxiang.com/yszcxcx.html')">

					<div class="fontS28 ">隐私政策</div>
					<div class="iconfont icon-youjiantou ml-auto"></div>
				</div>
				<div class="flex align-center lh-50 pt-20 pb-20 bor-b" @click="toSet('/pages/setting/about')">
					<div class="fontS28 ">关于我们</div>
					<div class="iconfont icon-youjiantou ml-auto"></div>
				</div>
				<div class="flex align-center lh-50 pt-20"
					@click="toSet('/pages/webView/webView?url=https://api.yijiangongxiang.com/fwyys.html')">
					<div class="fontS28 ">薪岗通服务条款</div>
					<div class="iconfont icon-youjiantou ml-auto"></div>
				</div>

			</view>

			<view class=" bg-fff p-30 mt-20" @click="toggleRole">
				<div class=" lh-50 ">
					<div class="fontS28 text-center color-orange">{{ userInfo.userType === '02' ? '切换到企业服务' : '切换到牛人端'
					}}
					</div>
				</div>
			</view>
			<view class=" bg-fff p-30 mt-20" @click="toOut">
				<div class=" lh-50 ">
					<div class="fontS28 text-center color-orange">注销账号</div>
				</div>
			</view>
			<view class=" bg-fff p-30 mt-20" @click="loginOut">
				<div class=" lh-50 ">
					<div class="fontS28 text-center color-orange">退出当前账号</div>
				</div>
			</view>


		</view>
	</view>
</template>

<script>
import {
	loginOut,
} from "@/api/user";
export default {

	data() {
		return {
			baseUrl: getApp().globalData.baseUrl,

		};
	},
	computed: {
		userInfo() {
			return this.$store.getters.userInfo || {};
		},
	},
	async onLoad() {
		this.postForm = this.userInfo
	},
	async onShow() {
		// await this.getUserInfo()
	},
	mounted() {

	},
	methods: {
		toggleRole() {
			uni.navigateTo({
				url: `/pages/index/load?userType=${this.userInfo.userType === '02' ? '03' : '02'}`
			})
		},
		loginOut() {
			uni.showModal({
				content: `您是否确认退出？`,
				confirmColor: '#3CC51F', // 确定按钮的文字颜色，默认为"#3CC51F"
				success: async (res) => {
					if (res.confirm) {
						const { data } = await loginOut()
						this.$chat?.logout();
						this.$store.commit("SET_USERINFO", {});
						uni.reLaunch({
							url: '/pages/login/login?type=loginOut'
						})
					} else if (res.cancel) {
						console.log('用户点击了取消按钮');
					}
				}
			})

		},
		toSet(url) {
			uni.navigateTo({
				url
			})
		},
		toOut() {
			uni.navigateTo({ url: '/pages/setting/loginOut' })
		},
		async getUserInfo() {
			const {
				data
			} = await getUserInfoApi({})
			this.postForm = data;
		},
		submit() {
			let params = {
				userHeaderUrl: this.postForm.userHeaderUrl,
				userName: this.postForm.userName,
				selfIntroduction: this.postForm.selfIntroduction,
				age: this.postForm.age,
				position: this.postForm.position,
				gender: this.postForm.gender
			}
			uni.showLoading({
				mask: true,
			});
			editUser(params).then((res) => {
				uni.hideLoading();
				uni.showToast({
					title: "修改成功",
					icon: "success",
				});
				getApp().globalData.mineTitleRefresh = true
				// this.$store.dispatch("getUserInfo");
				setTimeout(() => {
					uni.navigateBack({});
				}, 1000);
			});
		},


		upload() {
			var _this = this
			uni.chooseImage({
				count: 1,
				sourceType: ["album", "camera"],
				sizeType: ["original"], //compressed可以指定是原图还是压缩图，默认二者都有
				success: async (res) => {
					console.log(res.tempFilePaths[0])
					// uni.showLoading({
					// 	title: '图片上传中',
					// 	icon: 'loading'
					// })
					let form = encodeURIComponent(JSON.stringify(_this.postForm))
					uni.navigateTo({
						url: '/pages/mine/uploadImg?imgUrl=' + res.tempFilePaths[0] + '&postForm=' + form
					})
				},
				fail: () => {
					//处理如果没选择任何图片
					console.log("unChooseAnyimg");
					this.$emit("unChooseAnyimg");
				},
			});
		},
	},
};
</script>

<style lang="less" scoped>
@import url(user.less);
</style>
